package com.hy.controller;

import com.hy.common.Result;
import com.hy.entity.Comment;
import com.hy.service.CommentService;
import com.hy.dto.comment.CommentPageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 获取学习园地下的评论（分页，每条评论最多2条回复）
    @GetMapping("/studyGarden/{studyGardenId}")
    public Result<CommentPageDTO> getStudyGardenComments(
            @PathVariable Long studyGardenId,
            @RequestParam Integer page,
            @RequestParam Integer size) {
        return commentService.getStudyGardenComments(studyGardenId, page, size);
    }

    // 点赞接口（仅需评论ID）
    @PostMapping("/like/{commentId}")
    public Result<Boolean> likeComment(@PathVariable Long commentId) {
        return commentService.likeComment(commentId);
    }

    @PostMapping("/DeleteLike/{commentId}")
    public Result<Boolean> DeleteComment(@PathVariable Long commentId) {
        return commentService.DeleteComment(commentId);
    }


    // 获取周刊下的评论（分页，每条评论最多2条回复）
    @GetMapping("/weekly/{weeklyId}")
    public Result<CommentPageDTO> getWeeklyComments(
            @PathVariable Long weeklyId,
            @RequestParam Integer page,
            @RequestParam Integer size) {
        return commentService.getWeeklyComments(weeklyId,null ,page, size);
    }

    // 获取老师下的评论（分页，每条评论最多2条回复）
    @GetMapping("/teacher/{teacherId}")
    public Result<CommentPageDTO> getTeacherComments(
            @PathVariable Long teacherId,
            @RequestParam Integer page,
            @RequestParam Integer size) {
        return commentService.getWeeklyComments(null,teacherId, page, size);
    }

    // 发表评论/回复
    @PostMapping
    public Result<Boolean> addComment(@RequestBody Comment comment) {
        return commentService.addComment(comment);
    }

    // 获取某条评论下的所有回复（分页）
    @GetMapping("/replies/{commentId}")
    public Result<CommentPageDTO> getCommentReplies(
            @PathVariable Long commentId,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return commentService.getCommentReplies(commentId, pageNum, pageSize);
    }
}
